﻿using Newtonsoft.Json.Linq;

namespace YAPACS.RisServer.Services.ExtendCells;

/// <summary>
/// 标题单元格
/// </summary>
public class TitleCell : Cell
{
    private string _text;

    /// <summary>
    /// 文本
    /// </summary>
    public string Text
    {
        get => _text;
        set => SetText(value);
    }

    /// <summary>
    /// 构造
    /// </summary>
    /// <param name="text"></param>
    /// <param name="rowSpan"></param>
    public TitleCell(string text)
    {
        ClassName = "title-Row-Container-body";// 标题单元格样式
        Text = text;                           // 设置text，顺便生成body
        WidthCoculate();
        HeightCoculate();
    }

    /// <summary>
    /// 设置显示文字
    /// </summary>
    /// <param name="text"></param>
    public void SetText(string text)
    {
        _text = text;
        Body = new JObject
        {
            { "type", "tpl" },
            { "tpl", text },
            { "inline", false }
        };
    }

    public override void WidthCoculate()
    {
        Style ??= [];
        Style.Add("width", "100%");
    }
}
